VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "GameInputHitEventClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private refGameInput As dx_Input_Class  ' Referencia a la instacia de dx_Input_Class del programa.

Private keybHitState(255) As Boolean    ' Estados de las teclas del teclado.
Private mouseHitState As Mouse_Data     ' Estados de los botones del joystick.

' Inicializa la clase obteniendo la referencia a la instancia de la clase dx_Input_Class del programa:
Public Sub Initialize(GameInput As dx_Input_Class)
    Set refGameInput = GameInput
End Sub

' Evalua si la tecla del teclado ha sido presionada:
Public Function Key_Hit(Key As Key_Const) As Boolean
    If refGameInput.Key(Key) And Not keybHitState(Key) Then
        keybHitState(Key) = True
        Key_Hit = True
    End If
End Function

' Evalua si el boton del raton ha sido presionado:
Public Function Mouse_Hit(Button As Mouse_Button) As Boolean
    If (Button = Left_Button And refGameInput.Mouse.Left_Button) And Not mouseHitState.Left_Button Then
        mouseHitState.Left_Button = True
        Mouse_Hit = True
        
    ElseIf (Button = Right_Button And refGameInput.Mouse.Right_Button) And Not mouseHitState.Right_Button Then
        mouseHitState.Right_Button = True
        Mouse_Hit = True
        
    ElseIf (Button = Middle_Button And refGameInput.Mouse.Middle_Button) And Not mouseHitState.Middle_Button Then
        mouseHitState.Middle_Button = True
        Mouse_Hit = True
        
    End If
End Function

' Actualiza los estados de la clase:
Public Sub Update()
    Call UpdateKeyb
    Call UpdateMouse
End Sub

' Codigo encargado de actualizar los estados del teclado:
Private Sub UpdateKeyb()
    Dim Key As Long
    For Key = 0 To 255
        If Not refGameInput.Key(Key) And keybHitState(Key) Then keybHitState(Key) = False
    Next
End Sub

' Codigo encargado de actualizar los estados del raton:
Private Sub UpdateMouse()
    If Not refGameInput.Mouse.Left_Button And mouseHitState.Left_Button Then mouseHitState.Left_Button = False
    If Not refGameInput.Mouse.Right_Button And mouseHitState.Right_Button Then mouseHitState.Right_Button = False
    If Not refGameInput.Mouse.Middle_Button And mouseHitState.Middle_Button Then mouseHitState.Middle_Button = False
End Sub

' Destructor de la clase:
Private Sub Class_Terminate()
    Set refGameInput = Nothing
End Sub


